<?php

ini_set("display_errors", "on");

include dirname(__DIR__) . '/Lib/Autoloader.php';
use App\Config\YlyConfig;
use App\Oauth\YlyOauthClient;
use App\Api\PrintService;
use App\Api\PicturePrintService;
use App\Api\ExpressPrintService;

//'client_credentials' 自有型应用;
class Yprint{
	
	public static function prints($clientId,$clientSecret,$machine_code,$content,$origin_id,$access_token){
					
		$config = new YlyConfig($clientId, $clientSecret);				
		/**文本接口开始**/
		$print = new PrintService($access_token, $config);	
			
		try{			
			$res = $print->index($machine_code, $content, $origin_id);		
			return $res;
		}catch(Exception $e){
			$res['error']='1501';
			$res['error_description']='参数错误';
			return json_encode($res);
		}
		
	}
	
	public static function get_token($clientId,$clientSecret){
		/*$clientId = '';                                       //应用id
		$clientSecret = '';             //应用密钥*/
		$config = new YlyConfig($clientId, $clientSecret);
		$client = new YlyOauthClient($config);	
		try{
			$token = $client->getToken();
			return $token->access_token;
		}catch (Exception $e) {
			/*echo $e->getMessage() . "\n";
			print_r(json_decode($e->getMessage(), true));*/
			return 'error';
		}
	}
	
}
